Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Entry' - 12 code snippet(s) found

 Sample 1. Method to remove duplicates from a Map ( string and List of objects ) by matching the member field of the object.

Map<String,List<ClassInfoBean>> removeDuplicates(Map<String, List<ClassInfoBean>> interfaceMap){
   Map<String, List<ClassInfoBean>> interfaceMapWithoutDuplicate = new HashMap();
      
   for(Map.Entry<String, List<ClassInfoBean>> entry: interfaceMap.entrySet()){
      List<ClassInfoBean> classListWithoutDuplicate = new ArrayList();
      boolean alreadyContain = false;
      for(ClassInfoBean classes: entry.getValue()){
         for(ClassInfoBean classes1: classListWithoutDuplicate){
            if(classes1.name.equalsIgnoreCase(classes.name)){
               alreadyContain = true;
               break;
            }
         }
         if(alreadyContain == false){
            classListWithoutDuplicate.add(classes);
         }
      }
      interfaceMapWithoutDuplicate.put(entry.getKey(), classListWithoutDuplicate);
   }
      
   return interfaceMapWithoutDuplicate;
}

   Like      Feedback     map  map of list of objects  remove duplicates from map  Map.Entry


 Sample 2. Code Sample / Example / Snippet of org.apache.bcel.classfile.AnnotationEntry

    protected String dumpAnnotationEntries(final AnnotationEntry[] as)

{

final StringBuilder result = new StringBuilder();

result.append("[");

for (int i = 0; i < as.length; i++)

{

final AnnotationEntry annotation = as[i];

result.append(annotation.toShortString());

if (i + 1 < as.length) {

result.append(",");

}

}

result.append("]");

return result.toString();

}


   Like      Feedback      org.apache.bcel.classfile.AnnotationEntry


 Sample 3. Method to get a map of words and their count by passing in the string

Map<String,Integer> wordCountMap = new TreeMap();
String[] words = text.split(" ");
Set<Integer> countSet;
for(String word: words) {
if(wordCountMap.containsKey(word.toLowerCase())){
wordCountMap.put(word.toLowerCase(), wordCountMap.get(word.toLowerCase()).intValue() + 1);
} else {
wordCountMap.put(word.toLowerCase(), 1);
}
}

countSet = new TreeSet(Collections.reverseOrder());
countSet.addAll(wordCountMap.values());

for(Integer inte: countSet) {
for(Entry<String,Integer> entry: wordCountMap.entrySet()){
if(entry.getValue() == inte) {
System.out.println(entry);
}
}
}

   Like      Feedback     map  word count  map of string and integer  containsKey  string split  treeset  Collections.reverseOrder  set addAll   entry


 Sample 4. Make a Map entry read only using Apache Commons UnmodifiableMapEntry

Entry entry = new UnmodifiableMapEntry("Key2", "Value2");
entry.setValue("Value3"); // throws java.lang.UnsupportedOperationException

   Like      Feedback     read only map entry  UnmodifiableMapEntry  Apache commons collections


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 5. Cache Hibernate Entities using EHCache

// net.sf.ehcache.Cache.Cache(String name, int maxElementsInMemory, MemoryStoreEvictionPolicy 
memoryStoreEvictionPolicy, boolean overflowToDisk, String diskStorePath, boolean eternal, long
timeToLiveSeconds, long timeToIdleSeconds, boolean diskPersistent, long
diskExpiryThreadIntervalSeconds, RegisteredEventListeners registeredEventListeners)

Ehcache employeeCache = new Cache("Employee", 1000, MemoryStoreEvictionPolicy.FIFO, false, "c:/EmployeeDiskCacheStorage", false, 300,
300, false, 30, null);

employeeCache = new SelfPopulatingCache(employeeCache, new CacheEntryFactory() {
   @Override
   public Object createEntry(Object day) throws Exception {
      Employee employee = getEmployee(1234);
   return employee;
   }
});

CacheManager.getInstance().addCache(employeeCache);

   Like      Feedback     EHCache  cache hibernate entities  CacheManager  CacheEntryFactory  SelfPopulatingCache  MemoryStoreEvictionPolicy  net.sf.ehcache.Cache


 Sample 6. Code Sample / Example / Snippet of org.apache.bcel.generic.AnnotationEntryGen

    protected String dumpAnnotationEntries(final AnnotationEntryGen[] as)

{

final StringBuilder result = new StringBuilder();

result.append("[");

for (int i = 0; i < as.length; i++)

{

final AnnotationEntryGen annotation = as[i];

result.append(annotation.toShortString());

if (i + 1 < as.length) {

result.append(",");

}

}

result.append("]");

return result.toString();

}


   Like      Feedback      org.apache.bcel.generic.AnnotationEntryGen


 Sample 7. Code Sample / Example / Snippet of org.apache.commons.compress.archivers.ArchiveEntry

    private void addArchiveEntry(final ArchiveOutputStream out, final String filename, final File infile)

throws IOException, FileNotFoundException {

final ArchiveEntry entry = out.createArchiveEntry(infile, filename);

out.putArchiveEntry(entry);

IOUtils.copy(new FileInputStream(infile), out);

out.closeArchiveEntry();

archiveList.add(filename);

}


   Like      Feedback      org.apache.commons.compress.archivers.ArchiveEntry


 Sample 8. Code Sample / Example / Snippet of org.apache.commons.compress.archivers.tar.TarArchiveEntry

    protected String getExpectedString(final ArchiveEntry entry) {

if (entry instanceof TarArchiveEntry) {

final TarArchiveEntry tarEntry = (TarArchiveEntry) entry;

if (tarEntry.isSymbolicLink()) {

return tarEntry.getName() + " -> " + tarEntry.getLinkName();

}

}

return entry.getName();

}


   Like      Feedback      org.apache.commons.compress.archivers.tar.TarArchiveEntry


 Sample 9. Code Sample / Example / Snippet of org.apache.commons.compress.archivers.ar.ArArchiveEntry

    public void testLongFileNamesCauseExceptionByDefault() {

ArArchiveOutputStream os = null;

try {

os = new ArArchiveOutputStream(new ByteArrayOutputStream());

final ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt",

0);

os.putArchiveEntry(ae);

fail("Expected an exception");

} catch (final IOException ex) {

assertTrue(ex.getMessage().startsWith("filename too long"));

} finally {

closeQuietly(os);

}

}


   Like      Feedback      org.apache.commons.compress.archivers.ar.ArArchiveEntry


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 10. Code Sample / Example / Snippet of org.apache.commons.compress.archivers.zip.ZipArchiveEntry

    public void testCompressionMethod() throws Exception {

final ZipArchiveOutputStream zos =

new ZipArchiveOutputStream(new ByteArrayOutputStream());

final ZipArchiveEntry entry = new ZipArchiveEntry("foo");

assertEquals(-1, entry.getMethod());

assertFalse(zos.canWriteEntryData(entry));



entry.setMethod(ZipEntry.STORED);

assertEquals(ZipEntry.STORED, entry.getMethod());

assertTrue(zos.canWriteEntryData(entry));



entry.setMethod(ZipEntry.DEFLATED);

assertEquals(ZipEntry.DEFLATED, entry.getMethod());

assertTrue(zos.canWriteEntryData(entry));



entry.setMethod(6);

assertEquals(6, entry.getMethod());

assertFalse(zos.canWriteEntryData(entry));

zos.close();

}


   Like      Feedback      org.apache.commons.compress.archivers.zip.ZipArchiveEntry


 Sample 11. Code Sample / Example / Snippet of org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry

    public void testReadingBackLZMA2DictSize() throws Exception {

final File output = new File(dir, "lzma2-dictsize.7z");

final SevenZOutputFile outArchive = new SevenZOutputFile(output);

try {

outArchive.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 1 << 20)));

final SevenZArchiveEntry entry = new SevenZArchiveEntry();

entry.setName("foo.txt");

outArchive.putArchiveEntry(entry);

outArchive.write(new byte[] { 'A' });

outArchive.closeArchiveEntry();

} finally {

outArchive.close();

}



final SevenZFile archive = new SevenZFile(output);

try {

final SevenZArchiveEntry entry = archive.getNextEntry();

final SevenZMethodConfiguration m = entry.getContentMethods().iterator().next();

assertEquals(SevenZMethod.LZMA2, m.getMethod());

assertEquals(1 << 20, m.getOptions());

} finally {

archive.close();

}

}


   Like      Feedback      org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry


 Sample 12. Usage of

com.amazonaws.services.kinesis.AmazonKinesisClient
com.amazonaws.services.kinesis.model.PutRecordsRequest
com.amazonaws.services.kinesis.model.PutRecordsRequestEntry
com.amazonaws.services.kinesis.model.PutRecordsResult

PutRecordsRequestEntry entry = new PutRecordsRequestEntry();
entry.setPartitionKey(KEY);
entry.setData(VALUE.getBytes());

List<PutRecordsRequestEntry> entries = new ArrayList<PutRecordsRequestEntry>();
entries.add(entry);

PutRecordsRequest putRecordsRequest = new PutRecordsRequest();
putRecordsRequest.setStreamName(KINESIS-STREAM-NAME);
putRecordsRequest.setRecords(entries);

PutRecordsResult putRecordsResult = client.putRecords(putRecordsRequest);

   Like      Feedback     amazon kinesis   amazon aws   sending record to kinesis



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner